package com.qudian.pay.notify.dingtalk.demo;

import java.net.URLEncoder;
import java.util.ArrayList;
import org.junit.Test;
import com.qudian.pay.notify.dingtalk.DingtalkChatbotClient;
import com.qudian.pay.notify.dingtalk.SendResult;
import com.qudian.pay.notify.dingtalk.message.MarkdownMessage;

public class MarkdownMessageTest {
	
	private DingtalkChatbotClient client = new DingtalkChatbotClient();
	
	@Test
	public void testSendMarkdownMessage() throws Exception {
		MarkdownMessage message = new MarkdownMessage();
		message.setTitle("This is a markdown message");
		message.add(MarkdownMessage.getHeaderText(1, "header 1"));
		message.add(MarkdownMessage.getHeaderText(2, "header 2"));
		message.add(MarkdownMessage.getHeaderText(3, "header 3"));
		message.add(MarkdownMessage.getHeaderText(4, "header 4"));
		message.add(MarkdownMessage.getHeaderText(5, "header 5"));
		message.add(MarkdownMessage.getHeaderText(6, "header 6"));
		message.add(MarkdownMessage.getReferenceText("reference text"));
		message.add("\n\n");
		message.add("normal text");
		message.add("\n\n");
		message.add(MarkdownMessage.getBoldText("Bold Text"));
		message.add("\n\n");
		message.add(MarkdownMessage.getItalicText("Italic Text"));
		message.add("\n\n");
		ArrayList<String> orderList = new ArrayList<String>();
		orderList.add("order item1");
		orderList.add("order item2");
		message.add(MarkdownMessage.getOrderListText(orderList));
		message.add("\n\n");
		ArrayList<String> unorderList = new ArrayList<String>();
		unorderList.add("unorder item1");
		unorderList.add("unorder item2");
		message.add(MarkdownMessage.getUnorderListText(unorderList));
		message.add("\n\n");
		message.add(MarkdownMessage.getImageText("http://img01.taobaocdn.com/top/i1/LB1GCdYQXXXXXXtaFXXXXXXXXXX"));
		message.add(MarkdownMessage.getLinkText("This is a link", "dtmd://dingtalkclient/sendMessage?content=linkmessage"));
		message.add(MarkdownMessage.getLinkText("中文跳转", "dtmd://dingtalkclient/sendMessage?content=" + URLEncoder.encode("链接消息", "UTF-8")));
		SendResult result = client.send(WebhookConfig.testWebhook, message);
		System.out.println(result);
	}
}